package com.jokins.admin.vue.hefeng.Controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jokins.admin.vue.hefeng.Service.CityService;
import com.jokins.admin.vue.hefeng.param.CityParam;
import com.jokins.admin.vue.hefeng.vo.CityVo;
import com.jokins.common.util.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/hefeng/city")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping("/list")
    public ResultData getCityList(CityParam param) {
        final Page<Object> page = PageHelper.startPage(param.getCurrentPage(), param.getPageSize(), true);
        List<CityVo> cityVoList= cityService.getCityList(param);
        return ResultData.pageResponse(cityVoList, page.getTotal(), page.getPages(), page.getPageNum());
    }

    @GetMapping("/weatherList")
    public ResultData getWeatherList(@RequestParam String cityName) {
        List<CityVo> cityVoList= cityService.getWeatherList(cityName);
        return new ResultData("查询成功！",cityVoList);
    }
}
